﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the GNU General Public License version 2 (GPLv2).
// See accompanying file License.txt or copy at http://phuse.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Phuse.Net.Nntp
{
    using System.Collections.Generic;

    /// <summary>Is the base class for all NNTP commands that are non-pipelinable.</summary>
    /// <typeparam name="TResponse">The type of the response the command will produce.</typeparam>
    /// <remarks>See <see cref="NonPipelinableCommandBase{T, U}"/> for more information.</remarks>
    /// <threadsafety static="true" instance="false"/>
    public abstract class NonPipelinableCommand<TResponse> : NonPipelinableCommandBase<Client, TResponse>
        where TResponse : IResponse
    {
        /// <summary>Initializes a new instance of the <see cref="NonPipelinableCommand{TResponse}"/> class.</summary>
        protected NonPipelinableCommand()
        {
        }

        /// <summary>See <see cref="CommandBase{T, U}.IsMultilineResponse"/>.</summary>
        /// <returns><c>true</c> if the element at index 0 of <paramref name="initialResponseLineWords"/> is equal to
        /// one of the following: "100", "101", "211", "215", "220", "221", "222", "224", "225", "230", "231";
        /// <c>false</c> otherwise.</returns>
        /// <remarks>This base class implementation covers all standard response codes except for the GROUP command,
        /// see <see cref="GroupCommand.IsMultilineResponse"/> for more information. Non-standard commands can override
        /// as appropriate.</remarks>
        protected override bool IsMultilineResponse(IList<string> initialResponseLineWords)
        {
            return CommandHelper.IsMultilineResponse(initialResponseLineWords);
        }

        /// <summary>See <see cref="CommandBase{T, U}.ThrowOnError"/>.</summary>
        /// <remarks>Throws the indicated exception if the element at index 0 of
        /// <paramref name="initialResponseLineWords"/> matches one of the standard response codes in the following
        /// list:
        /// <list type="bullet">
        /// <item>"400": <see cref="ServiceUnavailableException"/></item>
        /// <item>"403": <see cref="ServerFaultException"/></item>
        /// <item>"411": <see cref="NoSuchGroupException"/></item>
        /// <item>"412": <see cref="NoGroupSelectedException"/></item>
        /// <item>"420": <see cref="InvalidCurrentArticleNumberException"/></item>
        /// <item>"421": <see cref="NoNextArticleException"/></item>
        /// <item>"422": <see cref="NoPreviousArticleException"/></item>
        /// <item>"423": <see cref="NoSuchArticleException"/></item>
        /// <item>"430": <see cref="NoSuchArticleException"/></item>
        /// <item>"440": <see cref="PostingNotPermittedException"/></item>
        /// <item>"441": <see cref="PostingFailedException"/></item>
        /// <item>"480": <see cref="MissingAuthenticationException"/></item>
        /// <item>"481": <see cref="AuthenticationFailedException"/></item>
        /// <item>"483": <see cref="MissingPrivacyException"/></item>
        /// <item>"500": <see cref="UnknownCommandException"/></item>
        /// <item>"502": <see cref="CommandNotPermittedException"/></item>
        /// <item>"503": <see cref="FeatureNotSupportedException"/></item>
        /// </list>
        /// Non-standard commands can override as appropriate.</remarks>
        protected override void ThrowOnError(IList<string> initialResponseLineWords)
        {
            CommandHelper.ThrowOnError(initialResponseLineWords);
        }
    }
}
